package com.bbx.taxi.client.Task;

import android.app.Activity;
import android.os.AsyncTask;

import com.bbx.api.sdk.model.official.passanger.Officail_OrderInfoBuild;
import com.bbx.api.sdk.model.official.passanger.Return.Officail_OrderInfo;
import com.bbx.api.sdk.model.official.passanger.Return.Officail_Price;
import com.bbx.api.sdk.model.official.passanger.Return.OrderList.OfficialOrderList;
import com.bbx.api.sdk.net.base.JsonBuild;
import com.bbx.api.sdk.net.official.passanger.Officail_OrderInfoNet;
import com.bbx.api.sdk.net.official.passanger.Officail_PriceNet;
import com.bbx.taxi.client.MyApplication;
import com.bbx.taxi.client.Bean.Value;

/**
 * @Path com.bbx.taxi.client.Task.MyOrderDetailTask.java
 * @Author 严旭文
 * @Date 2016-2-18 下午1:50:03
 * @Company 蓝海（福建）信息技术有限公司
 * @Description 订单详情，暂时只有订单审核有在用，后期订单详情都需要用
 */
public class MyOrderDetailTask {
	public static int STATUS_SUCCESS = 0;
	public static int STATUS_FAIL = -1;
	private Activity context;
	public OrderDetailTask mPriceTask;
	public static MyOrderDetailTask instance;

	public interface OrderDetailListener {
		/**
		 * 获取订单详情 status 0为成功,
		 */
		public void onOrderDetail(int status,
				OfficialOrderList mOfficialOrderList);
	}

	static OrderDetailListener mOrderDetailListener = null;

	public static void setOrderDetailListener(OrderDetailListener l) {
		mOrderDetailListener = l;
	}

	public static MyOrderDetailTask getInstance(Activity context,
			String order_id) {
		instance = new MyOrderDetailTask(context, order_id);
		return instance;
	}

	public MyOrderDetailTask(Activity context, String order_id) {
		this.context = context;
		getDetail(order_id);
	}

	public void getDetail(String order_id) {
		Officail_OrderInfoBuild mOfficail_OrderInfoBuild = new Officail_OrderInfoBuild(
				context);
		mOfficail_OrderInfoBuild.passenger_id = MyApplication.getInstance()
				.getUid();
		mOfficail_OrderInfoBuild.order_id = order_id;
		mPriceTask = new OrderDetailTask(context, mOfficail_OrderInfoBuild);
		mPriceTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
	}

	/**
	 * 获取订单详情
	 * 
	 */
	private class OrderDetailTask extends BaseAsyncTask {

		private Officail_OrderInfoBuild mOfficail_OrderInfoBuild;

		public OrderDetailTask(Activity context,
				Officail_OrderInfoBuild mOfficail_OrderInfoBuild) {
			super(context);
			this.mOfficail_OrderInfoBuild = mOfficail_OrderInfoBuild;
		}

		@Override
		public void onSuccess(Object object) {
			if (object != null) {
				Officail_OrderInfo mOfficail_OrderInfo = (Officail_OrderInfo) object;
				
				
				if (mOfficail_OrderInfo != null) {
					if (mOrderDetailListener != null) {
						mOrderDetailListener.onOrderDetail(STATUS_SUCCESS,
								mOfficail_OrderInfo.getInfo());
					}
				}else{
					if (mOrderDetailListener != null) {
						mOrderDetailListener.onOrderDetail(STATUS_FAIL, null);
					}
				}
			} else {
				if (mOrderDetailListener != null) {
					mOrderDetailListener.onOrderDetail(STATUS_FAIL, null);
				}
			}

		}

		@Override
		public void onFailed(int status, String msg) {
			if (mOrderDetailListener != null) {
				mOrderDetailListener.onOrderDetail(STATUS_FAIL, null);
			}

		}

		protected Object doInBackground(Object... params) {
			// TODO Auto-generated method stub
			String json = new JsonBuild().setModel(mOfficail_OrderInfoBuild)
					.getJson();
			return new Officail_OrderInfoNet(context, json);
		}
	}
}
